package com.idea.zd.sys.train.thread;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zzy
 * @Date 2020-03-31 09:45
 */
public class ThreadLocalTest {


}



class SynRunable implements Runnable{
    private ThreadLocal<Object> local=new ThreadLocal<>();

    @Override
    public void run() {
        Object bean = new Object();
        System.out.println(Thread.currentThread().getName() + ":" + bean.hashCode());
        local.set(bean);
        try {
            Thread.sleep(300);
            System.out.println(Thread.currentThread().getName() + ":" + local.get().hashCode());
            System.gc();
            Thread.sleep(300);
            System.out.println(Thread.currentThread().getName() + ":" + local.get().hashCode());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class Tests{

    public static void main(String[] args) {

        SynRunable target = new SynRunable();
        Thread threadA = new Thread(target, "AAAA");
        Thread threadB = new Thread(target, "BBBB");
        threadA.start();
        threadB.start();
    }
}
